package com.ssm.zyn.service.impl;

import com.ssm.zyn.dao.TeacherMapper;
import com.ssm.zyn.eo.TeacherEOpage;
import com.ssm.zyn.model.Teacher;
import com.ssm.zyn.service.Teacherservice;
import org.apache.ibatis.io.ExternalResources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实现业务及流程接口当中的内容
 */
@Service
public class TeacherServiceImpl implements Teacherservice {
    @Autowired
    private TeacherMapper teacherMapper;
    @Override
    public int AddtTeacher(Teacher teacher) {
        int returnInt=0;
        /**
         * 1.业务判断
         * （1）教师编号不能重复
         */
        //(1)判断角色
        int teacherIdCount=teacherMapper.getTeacherIdCount(teacher.getTeacherid());
        if (teacherIdCount<1){
            //2.数据的添加
            int addTeacherInt = teacherMapper.insertTeacher(teacher);
            //3.返回值的设置
            returnInt = addTeacherInt;
        }else {
            returnInt=-1;//有相同的教师编号
        }
        return returnInt;
    }

    @Override
    public int UpdateTeacher(Teacher teacher) {
        int isUpdate=0;
        /*1无业务判断*/
        try{
            isUpdate=teacherMapper.updateTeacher(teacher);
        }catch (Exception e){
            isUpdate = -1;
            //打印更新时报错的情况
            System.out.println("更新角色信息时执行SQL报错的原因为"+e.getMessage());
        }
        return isUpdate;
    }

    @Override
    public int DeleteTeacher(int tid) {
        int delTeacher=0;
        try {
            delTeacher=teacherMapper.delTeacher(tid);
        }catch (Exception e){
            delTeacher=-1;
            System.out.println("删除教师信息时执行SQL报错，信息为"+e.getMessage());
        }
        return delTeacher;
    }

    @Override
    public List<TeacherEOpage> getWhereAll(TeacherEOpage teacherEOpage) {
        List<TeacherEOpage> listTeacher= teacherMapper.getWhereAll(teacherEOpage);
        return listTeacher;
    }
}
